package com.softeem.gulimail.order.controller;


import com.softeem.gulimail.order.entity.OrderEntity;
import com.softeem.gulimail.order.entity.OrderReturnReasonEntity;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.UUID;

@RestController
public class RabbitController {
    @Autowired
    private RabbitTemplate template;
    @GetMapping("/get")
    public String sendMessage(@RequestParam(value = "num",defaultValue = "10") int num){
        for(int i=0;i<num;i++){
            if(i%2==0){
                OrderEntity orderEntity = new OrderEntity();
                orderEntity.setOrderSn(UUID.randomUUID().toString());
                template.convertAndSend("directExchange","directRoutingKey",orderEntity);
            }else {
                OrderReturnReasonEntity orderReturnReasonEntity = new OrderReturnReasonEntity();
                orderReturnReasonEntity.setId(11l);
                orderReturnReasonEntity.setName("哈哈");
                orderReturnReasonEntity.setCreateTime(new Date());
                template.convertAndSend("directExchange","directRoutingKey",orderReturnReasonEntity);
            }
        }
        return "ok";

    }
}
